package scct.hys.utils;

import java.sql.*;

public class DBUtils {
    private static String Driver="com.mysql.cj.jdbc.Driver";
    private static String dbUrl =
            "jdbc:mysql://localhost:3306/theaterdb?characterEncoding=UTF-8&useSSL=false";
    private static  String name="root";
    private static  String pass="123456";
//    连接数据库
    public static Connection getConnection()  {
        Connection conn;
        try{
            Class.forName(Driver);//加载驱动
            conn= DriverManager.getConnection(dbUrl,name,pass);
        }catch (ClassNotFoundException | SQLException e){
            throw new RuntimeException(e);
        }
        return conn;
    }
    //    关闭数据库
    public static void closeConnection(Connection conn){
        if(conn!=null){
            try{
                conn.close();
            }catch (SQLException e){
                throw new RuntimeException(e);
            }
        }
    }


    public static String getDriver() {
        return Driver;
    }

    public static void setDriver(String driver) {
        Driver = driver;
    }

    public static String getDbUrl() {
        return dbUrl;
    }

    public static void setDbUrl(String dbUrl) {
        DBUtils.dbUrl = dbUrl;
    }

    public static String getName() {
        return name;
    }

    public static void setName(String name) {
        DBUtils.name = name;
    }

    public static String getPass() {
        return pass;
    }

    public static void setPass(String pass) {
        DBUtils.pass = pass;
    }

    public static void close(Connection conn, Statement stmt, ResultSet rs) {
    }
}
